package logic

import (
	"context"
	"house123/C/srv/model/mysql"

	"house123/C/srv/house"
	"house123/C/srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsInfoLogic {
	return &GoodsInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsInfoLogic) GoodsInfo(in *house.GoodsInfoRequest) (*house.GoodsInfoResponse, error) {
	// todo: add your logic here and delete this line
	g := []mysql.Goods{}

	mysql.DB.Where("id=?", in.GoodsId).Find(&g)
	var goodss []*house.GoodsList
	for _, good := range g {
		list := house.GoodsList{
			Title:     good.Title,
			Cover:     good.Cover,
			Price:     float32(good.Price),
			LikeHouse: good.LikeHouse,
			Status:    good.Status,
		}
		goodss = append(goodss, &list)
	}
	return &house.GoodsInfoResponse{List: goodss}, nil
}
